<?php
/**
 * 关键词商品查询接口【申请】 jd.union.open.goods.query
 *
 * See: https://union.jd.com/openplatform/api/628
 * User: Ken.Zhang <kenphp@yeah.net>
 * Date: 2019-05-12
 */
class UnionOpenGoodsQueryRequest {

    /**
     * 一级类目id
     */
    private $cid1;

    /**
     * 二级类目id
     */
    private $cid2;

    /**
     * 三级类目id
     */
    private $cid3;

    /**
     * 页码
     */
    private $pageIndex;

    /**
     * 每页数量，单页数最大30，默认20
     */
    private $pageSize;

    /**
     * skuid集合(一次最多支持查询100个sku)，数组类型开发时记得加[]
     */
    private $skuIds;

    /**
     * 关键词，字数同京东商品名称一致，目前未限制
     */
    private $keyword;

    /**
     * 商品价格下限
     */
    private $pricefrom;

    /**
     * 商品价格上限
     */
    private $priceto;

    /**
     * 佣金比例区间开始
     */
    private $commissionShareStart;

    /**
     * 佣金比例区间结束
     */
    private $commissionShareEnd;

    /**
     * 商品类型：自营[g]，POP[p]
     */
    private $owner;

    /**
     * 排序字段
     * price：单价,
     * commissionShare：佣金比例,
     * commission：佣金，
     * inOrderCount30Days：30天引单量，
     * inOrderComm30Days：30天支出佣金
     */
    private $sortName;

    /**
     * asc,desc升降序,默认降序
     */
    private $sort;

    /**
     * 是否是优惠券商品，1：有优惠券，0：无优惠券
     */
    private $isCoupon;

    /**
     * 是否是拼购商品，1：拼购商品，0：非拼购商品
     */
    private $isPG;

    /**
     * 拼购价格区间开始
     */
    private $pingouPriceStart;

    /**
     * 拼购价格区间结束
     */
    private $pingouPriceEnd;

    /**
     * 是否是爆款，1：爆款商品，0：非爆款商品
     */
    private $isHot;

    /**
     * 品牌code
     */
    private $brandCode;

    /**
     * 店铺Id
     */
    private $shopId;

    /**
     * 请求参数
     */
    public $apiParams = [];

    public function setCid1($cid1)
    {
        $this->cid1 = $cid1;
        $this->apiParams['goodsReqDTO']['cid1'] = $cid1;
    }

    public function getCid1()
    {
        return $this->cid1;
    }

    public function setCid2($cid2)
    {
        $this->cid2 = $cid2;
        $this->apiParams['goodsReqDTO']['cid2'] = $cid2;
    }

    public function getCid2()
    {
        return $this->cid2;
    }

    public function setCid3($cid3)
    {
        $this->cid3 = $cid3;
        $this->apiParams['goodsReqDTO']['cid3'] = $cid3;
    }

    public function getCid3()
    {
        return $this->cid3;
    }

    public function setPageIndex($page_index)
    {
        $this->pageIndex = $page_index;
        $this->apiParams['goodsReqDTO']['pageIndex'] = $page_index;
    }

    public function getPageIndex()
    {
        return $this->pageIndex;
    }

    public function setPageSize($page_size)
    {
        $this->pageSize = $page_size;
        $this->apiParams['goodsReqDTO']['pageSize'] = $page_size;
    }

    public function getPageSize()
    {
        return $this->pageSize;
    }

    public function setSkuIds($skuIds)
    {
        $this->skuIds = $skuIds;
        $this->apiParams['goodsReqDTO']['skuIds'] = $skuIds;
    }

    public function getSkuIds()
    {
        return $this->skuIds;
    }

    public function setKeyword($keyword)
    {
        $this->keyword = $keyword;
        $this->apiParams['goodsReqDTO']['keyword'] = $keyword;
    }

    public function getKeyword()
    {
        return $this->keyword;
    }

    public function setPricefrom($pricefrom)
    {
        $this->pricefrom = $pricefrom;
        $this->apiParams['goodsReqDTO']['pricefrom'] = $pricefrom;
    }

    public function getPricefrom()
    {
        return $this->pricefrom;
    }

    public function setPriceto($priceto)
    {
        $this->priceto = $priceto;
        $this->apiParams['goodsReqDTO']['priceto'] = $priceto;
    }

    public function getPriceto()
    {
        return $this->priceto;
    }

    public function setCommissionShareStart($commissionShareStart)
    {
        $this->commissionShareStart = $commissionShareStart;
        $this->apiParams['goodsReqDTO']['commissionShareStart'] = $commissionShareStart;
    }

    public function getCommissionShareStart()
    {
        return $this->commissionShareStart;
    }

    public function setCommissionShareEnd($commissionShareEnd)
    {
        $this->commissionShareEnd = $commissionShareEnd;
        $this->apiParams['goodsReqDTO']['commissionShareEnd'] = $commissionShareEnd;
    }

    public function getCommissionShareEnd()
    {
        return $this->commissionShareEnd;
    }

    public function setOwner($owner)
    {
        $this->owner = $owner;
        $this->apiParams['goodsReqDTO']['owner'] = $owner;
    }

    public function getOwner()
    {
        return $this->owner;
    }

    public function setSortName($sortName)
    {
        $this->sortName = $sortName;
        $this->apiParams['goodsReqDTO']['sortName'] = $sortName;
    }

    public function getSortName()
    {
        return $this->sortName;
    }

    public function setSort($sort)
    {
        $this->sort = $sort;
        $this->apiParams['goodsReqDTO']['sort'] = $sort;
    }

    public function getSort()
    {
        return $this->sort;
    }

    public function setIsCoupon($isCoupon)
    {
        $this->isCoupon = $isCoupon;
        $this->apiParams['goodsReqDTO']['isCoupon'] = $isCoupon;
    }

    public function getIsCoupon()
    {
        return $this->isCoupon;
    }

    public function setIsPG($isPG)
    {
        $this->isPG = $isPG;
        $this->apiParams['goodsReqDTO']['isPG'] = $isPG;
    }

    public function getIsPG()
    {
        return $this->isPG;
    }

    public function setPingouPriceStart($pingouPriceStart)
    {
        $this->pingouPriceStart = $pingouPriceStart;
        $this->apiParams['goodsReqDTO']['pingouPriceStart'] = $pingouPriceStart;
    }

    public function getPingouPriceStart()
    {
        return $this->pingouPriceStart;
    }

    public function setPingouPriceEnd($pingouPriceEnd)
    {
        $this->pingouPriceEnd = $pingouPriceEnd;
        $this->apiParams['goodsReqDTO']['pingouPriceEnd'] = $pingouPriceEnd;
    }

    public function getPingouPriceEnd()
    {
        return $this->pingouPriceEnd;
    }

    public function setIsHot($isHot)
    {
        $this->isHot = $isHot;
        $this->apiParams['goodsReqDTO']['isHot'] = $isHot;
    }

    public function getIsHot()
    {
        return $this->isHot;
    }

    public function setBrandCode($brandCode)
    {
        $this->brandCode = $brandCode;
        $this->apiParams['goodsReqDTO']['brandCode'] = $brandCode;
    }

    public function getBrandCode()
    {
        return $this->brandCode;
    }

    public function setShopId($shop_id)
    {
        $this->shopId = $shop_id;
        $this->apiParams['goodsReqDTO']['shopId'] = $shop_id;
    }

    public function getShopId()
    {
        return $this->shopId;
    }

    public function getApiMethodName()
    {
        return 'jd.union.open.goods.query';
    }

    /**
     * 解析结果
     *
     * @param   string      $response
     * @throws  Exception
     * @return  mixed
     */
    public function getResult($response)
    {
        $responseKey = str_replace('.', '_', $this->getApiMethodName()) . '_response';

        $response = @json_decode($response, true);
        if (!array_key_exists($responseKey, $response))
            $resp = $response['errorResponse'];
        else {
            $response[$responseKey]['result'] = json_decode($response[$responseKey]['result']);

            $resp = $response[$responseKey];
        }

        return $resp;
    }

}